Skip to content

feat(auth): Ensure new auth SDK versions are backwards compatible with previous SDKs to enable copying to G3#17407

Open
macastelaz wants to merge 8 commits into
mainfrom
copy_updates
Open

feat(auth): Ensure new auth SDK versions are backwards compatible with previous SDKs to enable copying to G3#17407
macastelaz wants to merge 8 commits into
mainfrom
copy_updates

Conversation

@macastelaz

Copy link
Copy Markdown
Contributor

Incorporate universal bug fixes, robustness guardrails, and circular import decoupling

  • Restore fail-fast validation in _mtls_helper.py
  • Add robustness guardrails to impersonated_credentials.py for universe_domain
  • Safeguard RSA Signer & key_id in rsa.py
  • Break circular import in credentials.py
  • Update unit tests in test__mtls_helper.py to match new behavior and run robustly in Google environments.

TAG=agy
CONV=39c1761f-e06b-4e3a-80b6-b4fbc70df0b6

…nd circular import decoupling

- Restore fail-fast validation in _mtls_helper.py
- Add robustness guardrails to impersonated_credentials.py for universe_domain
- Safeguard RSA Signer & key_id in rsa.py
- Break circular import in credentials.py
- Update unit tests in test__mtls_helper.py to match new behavior and run robustly in Google environments.

TAG=agy
CONV=39c1761f-e06b-4e3a-80b6-b4fbc70df0b6

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces dynamic imports for regional access boundary lookups, adds robust environment variable validation for client certificates, and improves fallback handling for universe domains and key IDs. The review feedback highlights opportunities to make the code more robust and efficient, such as performing safe None checks before accessing object properties in rsa.py, avoiding falsy value issues when retrieving key_id, and eliminating redundant attribute lookups in impersonated_credentials.py.

Comment thread packages/google-auth/google/auth/crypt/rsa.py Outdated
Comment thread packages/google-auth/google/auth/crypt/rsa.py Outdated
Comment thread packages/google-auth/google/auth/impersonated_credentials.py
…s module attribute

TAG=agy
CONV=39c1761f-e06b-4e3a-80b6-b4fbc70df0b6
…ey_id

TAG=agy
CONV=39c1761f-e06b-4e3a-80b6-b4fbc70df0b6
…impersonated credentials

TAG=agy
CONV=39c1761f-e06b-4e3a-80b6-b4fbc70df0b6
TAG=agy
CONV=39c1761f-e06b-4e3a-80b6-b4fbc70df0b6
TAG=agy
CONV=39c1761f-e06b-4e3a-80b6-b4fbc70df0b6
raise ValueError(
"Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be"
" either `true` or `false`"
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should be reverting this kind of behaviour. It was an explicit decision to return False instead of raise an exception here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you by chance have any additional context you could share on the original decision to return False here? From my view point, it feels like a security risk to not fail fast here. E.g. if a user sets this to ture trying to set the desire to use a client cert for an mtls connection and we silently "downgrade" this to false because of the typo, I'm not sure it's a great result. By raising here, we fail fast and close that "hole".

FWIW, there are internal tests for gapic generated clients that are asserting an error is raised so if we do stick with returning false, we'll likely need to update a lot of older APIs, etc.

FWIW, we currently have a discrepancy in

which raises the error as well as in the gapic generator ( )

elif module_str.startswith(RSA_KEY_MODULE_PREFIX):
elif private_key is None or private_key.__class__.__module__.startswith(
RSA_KEY_MODULE_PREFIX
):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change, someone would get an ImportError if they called RSASigner(None) without the rsa library installed. That doesn't seem right

Can we make the class use the default _cryptography_rsa implementation if None is passed? Or otherwise refactor the class to support None?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call - fixed this to use the default implementation in the case of None

def key_id(self):
key_id = getattr(self, "_key_id", None)
if key_id is not None:
return key_id

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this to support subclasses? (If so, maybe add a comment?)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment

universe_domain
if isinstance(universe_domain, str)
else credentials.DEFAULT_UNIVERSE_DOMAIN
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like it could be a pretty big behaviour change. Are you sure this is safe?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be safe (I know, famous last words): the base credential class already sets this same default (

self._universe_domain = DEFAULT_UNIVERSE_DOMAIN
) and if the universe domain is set to something else, it would still be respected here. There are cases where you have an older custom credential class or what we encountered in mock credentials used in tests where the universe domain isn't set and the class doesn't extend the base, but I think even in these cases, using DEFAULT_UNIVERSE_DOMAIN is expected across Google client libraries.

Thoughts?

…to avoid ImportError

TAG=agy
CONV=39c1761f-e06b-4e3a-80b6-b4fbc70df0b6
…key_id

TAG=agy
CONV=39c1761f-e06b-4e3a-80b6-b4fbc70df0b6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants